var OrderProgressInfo = function (order) {
  BaseModel.call(this);

  var self = this;
  var fn = {
    initData: function (order) {
      var fields = ['companyOrderId', 'factoryId', 'customerId', 'equipmentNo', 'createUser',
        'orderCount', 'feedCount'
      ];
      self.setDataFromObj(order, fields);

      var count = order.count;
      if (count === null || count < 0) {
        count = 0;
      }
      self.count = count;

      var startTime = order.startTime;
      self.startTime = moment(startTime).valueOf();

      var endTime = order.endTime;
      self.endTime = moment(endTime).valueOf();

      self.id = SysUtil.getId();
      self.status = '';
    }
  };

  this.setEquipmentStatus = function(data){
    if (data === null) {
      return;
    }

    var status = data.status;
    if (SysUtil.isEmpty(status)) {
      status = '';
    } else {
      if (status === '运行') {
        var nowTime = data.nowTime;
        var workTime = data.processMaxWorkingTime;
        if (!SysUtil.isEmpty(nowTime) && !SysUtil.isEmpty(workTime) && workTime>0){
          nowTime = moment(nowTime).startOf('second').valueOf();
          var rangeTime = moment().diff(nowTime,'second');
          if (rangeTime > workTime) {
            status = '待机';
          }
        }
      }
    }
    this.status = status;

    var statusObj = {
      "1": "运行",
      "2": "待机",
      "3": "警报",
      "4": "离线",
      "5": "暂停"
    };
    var statusCode = '';
    for (var code in statusObj) {
      var value = statusObj[code];
      if (status === value) {
        statusCode = code;
        break;
      }
    }
    this.statusCode = statusCode;
  }

  fn.initData(order);
};
